package com.lly.songhigh.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.lly.songhigh.R;
import com.lly.songhigh.adapter.AlbumGridViewAdapter;
import com.lly.songhigh.adapter.MVDetialsListViewAdapter;
import com.lly.songhigh.adapter.SingerInformationAdapter;
import com.lly.songhigh.application.BaseApplication;
import com.lly.songhigh.entity.SingerAlbum;
import com.lly.songhigh.entity.SingerInformation;
import com.lly.songhigh.volley.VolleySingleton;

import java.util.List;

/**
 * Created by 遇博 on 15/10/27.
 */
public class SingerInformationFragment extends Fragment {
    private String inforUrl;
    private ListView single_information_listView;
    private TextView singer_introduce, singer_life;
    private VolleySingleton volleySingleton;
    private List<SingerInformation>  singerInfor;
    private SingerInformation.DataEntity  singer;
    private SingerInformationAdapter  adapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.singer_information_fragment, null);
        initView(view);
        initData();
        return view;
    }
    private void initView(View view) {
        Bundle bundle = getArguments();
        inforUrl = bundle.getString("inforUrl");
        BaseApplication.getInstance().addActivity(getActivity());
        volleySingleton = VolleySingleton.getInstance();
//        single_information_listView = (ListView) view.findViewById(R.id.single_information_listView);
        singer_introduce = (TextView) view.findViewById(R.id.singer_introduce);
        singer_life = (TextView) view.findViewById(R.id.singer_life);
    }
    private void initData() {
        StringRequest request = new StringRequest(inforUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                if (response != null) {
                    Gson gson = new Gson();
                    SingerInformation result = gson.fromJson(response, SingerInformation.class);
                    if (result != null && result.getData() != null) {
                        singer = result.getData();
                        Log.i("++++++", response);
//                        adapter = new SingerInformationAdapter(getActivity(), singer);
//                        single_information_listView.setAdapter(adapter);
                        if(singer != null){
                            setViewContent(singer);
                        }
                    }
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        });
        volleySingleton.addQueue(request);
    }
    private void setViewContent(SingerInformation.DataEntity singer) {

        singer_introduce.setText(singer.getBrief());
        singer_life.setText(singer.getPersonalLife());
//        achievements.setText(singer.getAchievements());
//        englishName.setText(singer.getEnglishName());
//        birthDate.setText(singer.getBirthDate());
//        nationality.setText(singer.getCountry());
//        nation.setText(singer.getNation());
//        birthPlace.setText(singer.getBirthPlace());
//        height.setText(singer.getHeight() + "米");
//        weight.setText(singer.getWeight() + "千克");
//        bloodType.setText(singer.getBloodType());
//        school.setText(singer.getSchool());
//        commissionBroker.setText(singer.getCompanyName());
//        profession.setText(singer.getCareer());
    }

}


